﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.ApplicationPages.Calendar.RecurrenceRule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindStyle.SPCalendar
{
    public static class Utility
    {
        internal static string ToSPString(this DaysOfWeek specialDay)
        {
            switch (specialDay)
            {
                case DaysOfWeek.Weekday:
                    return "weekday";
                case DaysOfWeek.WeekendDay:
                    return "weekend_day";
                case DaysOfWeek.Day:
                    return "day";
                default:
                    return specialDay.ToString().ToLower().Substring(0, 2);
            }
        }

        internal static bool HasFlag(this DaysOfWeek source, DaysOfWeek member)
        {
            return (source & member) == member;
        }

        internal static DaysOfWeek ParseDayOfWeek(DayOfWeek day)
        {

            switch (day)
            {
                case DayOfWeek.Monday:
                    return DaysOfWeek.Monday;
                case DayOfWeek.Tuesday:
                    return DaysOfWeek.Tuesday;
                case DayOfWeek.Wednesday:
                    return DaysOfWeek.Wednesday;
                case DayOfWeek.Thursday:
                    return DaysOfWeek.Thursday;
                case DayOfWeek.Friday:
                    return DaysOfWeek.Friday;
                case DayOfWeek.Saturday:
                    return DaysOfWeek.Saturday;
                case DayOfWeek.Sunday:
                    return DaysOfWeek.Sunday;
                default:
                    return DaysOfWeek.None;
            }
        }

        internal static Ordinal ParseOrdinal(RecurrenceRule.OrdinalType ordinal)
        {
            switch (ordinal)
            {
                case RecurrenceRule.OrdinalType.Second:
                    return Ordinal.Second;
                case RecurrenceRule.OrdinalType.Third:
                    return Ordinal.Third;
                case RecurrenceRule.OrdinalType.Fourth:
                    return Ordinal.Fourth;
                case RecurrenceRule.OrdinalType.Last:
                    return Ordinal.Last;
                default:
                    return Ordinal.First;
            }
        }
    }
}
